﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="addnews.aspx.cs" Inherits="UI.system.addnews" ValidateRequest="false" %>
<%@ Import Namespace="Model" %>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="lib/icheck/icheck.css" rel="stylesheet" type="text/css" />
<link href="lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
<link href="lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="lib/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="lib/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" src="lib/ueditor/lang/zh-cn/zh-cn.js"></script>

<!--[if IE 6]>
<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>添加资讯</title>
</head>
<body>
<div class="pd-20">
  <form action="" method="post" class="form form-horizontal" id="form-user-add">
    <div class="row cl">
      <label class="form-label col-2"><span class="c-red">*</span>资讯标题：</label>
      <div class="formControls col-5">
        <input type="text" class="input-text" value="<%=product.name %>" placeholder="" datatype="*" nullmsg="名称不能为空！"  id="txt_name" name="product-category-name">
      </div>
      <div class="col-5"> </div>
    </div>
    <div class="row cl">
      <label class="form-label col-2"><span class="c-red">*</span>图片：</label>
      <div class="formControls col-5">
        <div id="upload_products" class='upload_product <%=string.IsNullOrEmpty(product.img)?"":"hidden" %>'><div id="upload_product"></div></div>
                 <div id="upload_show" class='upload_show <%=string.IsNullOrEmpty(product.img)?"hidden":"" %>'>
                     <div id="img_container" class="img_container"><img src="<%=product.img %>"/></div>
                     <div class="reupload"><a href="javascript:Re_Upload()">重传</a></div>
                 </div> <div style="float:left; color:red; padding-top:5px; font-size:12px; padding-left:10px;">推荐大小：700*440</div>
      </div>
      <div class="col-5"> </div>
    </div> 
    <div class="row cl">
      <label class="form-label col-2">点击量：</label>
      <div class="formControls col-5">
        <input type="text" class="input-text" value="<%=product.click %>" placeholder=""   id="txt_count" name="product-category-name">
      </div>
      <div class="col-5"> </div>
    </div>
    
    <div class="row cl">
      <label class="form-label col-2">内容：</label>
      <div class="formControls col-5">
        <script id="editor" type="text/plain" style="width:100%;height:400px;"><%=product.context %></script>
      </div>
      <div class="col-5"></div>
    </div>
    <div class="row cl">
      <div class="col-9 col-offset-2">
        <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
      </div>
    </div>
  </form>
</div>
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="lib/icheck/jquery.icheck.min.js"></script> 
<script type="text/javascript" src="lib/Validform/5.3.2/Validform.min.js"></script>
<script type="text/javascript" src="lib/layer/1.9.3/layer.js"></script>
<script type="text/javascript" src="js/H-ui.js"></script>
<script type="text/javascript" src="js/H-ui.admin.js"></script>
<script src="/js/swfupload.js"></script>
<script type="text/javascript">
    var id = "<%=id %>";
    var old_img = "<%=product.img %>";
    $(function () {
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });
        $("#form-user-add").Validform({
            tiptype: 2,
            callback: function (form) {
                var data = {};
                data.act = "Save_News";
                data.name = $("#txt_name").val();
                data.context = ue.getContent();
                data.id = id;
                data.click = $("#txt_count").val();
                data.img = $(".img_container img").attr("src");
                if (old_img == data.img) {
                    data.imgchange = false;
                }
                else {
                    data.imgchange = true;
                }

                data.old_img = old_img; //如果修改了图片，把旧照片传给服务器，删除掉
                data.context = escape(ue.getContent());
                Ajax.Post("/system/tools/Admin.ashx", data, function (r) {
                    var json = $.parseJSON(r);
                    if (json.state) {
                        layer.msg('已成功!', { icon: 1, time: 1000 }, function () {
                            window.location.href = "/system/make.aspx?flag=all";
                        });
                        
                    }
                    else {
                        layer.msg(json.msg, { icon: 2, time: 1000 });
                    }
                });
                return false; //必写
            }
        });
        var ue = UE.getEditor('editor');
    });
    function Upload_File(id, type, width, height, img, multiple, panel, text) {
        var swfs;
        this.swfu = swfs;
        var file_types = "*.jpg;*.gif;*.png;*.jpeg;*.bmp";
        var file_width = 25;
        var file_height = 25;
        var file_img = "/img/adduploads.gif";
        var file_multiple = SWFUpload.BUTTON_ACTION.SELECT_FILE;
        var file_text = "";
        var allsize = 0;
        var hasload = 0;
        if (type) {
            file_types = type;
        }
        if (width) {
            file_width = width;
        }
        if (height) {
            file_height = height;
        }
        if (img) {
            file_img = img;
        }
        if (multiple) {
            file_multiple = SWFUpload.BUTTON_ACTION.SELECT_FILES;
        }
        if (text) {
            file_text = text;
        }
        var swfuOption = {//swfupload选项
            upload_url: "/system/tools/Upload.ashx", //接收上传的服务端url
            flash_url: "/js/swfupload.swf", //swfupload压缩包解压后swfupload.swf的url
            button_placeholder_id: id, //上传按钮占位符的id
            file_size_limit: "200MB", //用户可以选择的文件大小，有效的单位有B、KB、MB、GB，若无单位默认为KB
            file_upload_limit: 0,  // 上传文件的总个数
            file_queue_limit: 0,   // 每次能上传的文件个数
            file_types: file_types,
            custom_settings: {
                progressTarget: "fsUploadProgress",
                cancelButtonId: "btnCancel"
            },
            post_params: {
                "ASPSESSID": "<%=Session.SessionID %>"
            },
            multiple: true,
            button_width: file_width, //按钮宽度
            button_height: file_height, //按钮高度
            button_action: file_multiple,
            //button_action: SWFUpload.BUTTON_ACTION.SELECT_FILE,  //单选
            //button_action: SWFUpload.BUTTON_ACTION.SELECT_FILES, //多选
            button_image_url: file_img,
            button_text_style: '.button{color:#ffffff;font-size:12px;}',
            button_text: "<span class='button'>" + file_text + "</span>", //按钮文字
            button_cursor: SWFUpload.CURSOR.HAND,
            upload_success_handler: uploadSuccess, //文件上传成功
            upload_complete_handler: uploadComplete,
            file_queued_handler: fileQueued,
            upload_progress_handler: uploadProgress,
            file_queue_error_handler: fileQueueError,
            file_dialog_complete_handler: fileDialog,
            file_dialog_start_handler: prevDialog,
            file_dialog_complete_handler: afterDialog,
            debug: false
        };

        function uploadSuccess(file, serverData) {
            var json = $.parseJSON(serverData);
            if (json.length > 0) {
                if (this.handle == "upload_product") {
                    $("#upload_products").addClass("hidden");
                    $("#upload_show").removeClass("hidden");
                    $("#img_container").html("<img src='" + json[0] + "'/>");
                } else if (this.handle == "upload_annex") {
                    $(".upload_product").addClass("hidden");
                    $(".upload_show").removeClass("hidden");
                    $(".img_container div").attr("class", Get_Icon(json[0]));
                    $(".img_container").attr("val", json[0]);
                } else if (this.handle == "upload_img") {
                    var info = json[0];
                    var dian = info.lastIndexOf(".");
                    $("#" + file.id).attr("src", info.substring(0, dian) + "_50" + info.substring(dian, info.length)).attr("val", info).css("margin-top", "0px").parent().css("border", "1px solid #fff");
                }
                else if (this.handle == "upload_file") {
                    var info = json[0];
                    $("#" + file.id).attr("val", info);
                }
                else if (this.handle == "upload_logo") {
                    var info = json[0];
                    $("#companylogo").attr("src", info);
                    $(".topmenu .logo img").attr("src", info);
                    LayerBox.Close.ByAll();
                    LayerBox.Msg.Success("保存成功");
                }
                else if (this.handle == "upload_video") {
                    var video = json[0].split(',');
                    $("#" + file.id).attr("path", video[0]).attr("vname", video[1]);
                }
            }
        };
        function afterDialog() {
            if (this.handle == "upload_img" || this.handle == "upload_file") {
                InitSize();
            }
            var option = {};
            var date = new Date();
            option.handle = this.handle;
            option.random = date.Format("hhmmss");
            swfs.setPostParams(option);

            if (this.handle == "upload_img" || this.handle == "upload_product" || this.handle == "upload_annex" || this.handle == "upload_logo" || this.handle == "upload_video") {
                swfs.startUpload();

            }


        };
        function uploadComplete(file) {
            if (swfs.getStats().files_queued > 0) {  //没有这句，则只上传第一个文件
                swfs.startUpload();
            } else {
                if (this.handle == "upload_file") {
                    $("#" + this.submitid).attr("filesuccess", "true");
                    $("#" + this.submitid).click();
                    allsize = 0;
                    hasload = 0;
                }

            }
        };
        function fileQueued(file) {
            if (this.handle == "upload_img") {
                Init_Img(panel, file);
            }
            if (this.handle == "upload_file") {
                Init_File(panel, file);
                allsize += file.size;
            }
            if (this.handle == "upload_logo") {
                var index = LayerBox.Load("正在保存公司logo...");
            }
            if (this.handle == "upload_video" || this.handle == "upload_video2") {
                $("#video_container").append('<div class="img"><img src="/img/video.jpg"/><span id="' + file.id + '" onclick="remove_img2(this)"></span><div class="video"><div class="percent"></div></div></div>');
            }
            if (this.handle == "upload_video") {
                $("#upload_videopanel").css("visibility", "hidden");
            }
        };
        function uploadProgress(file, bytesLoaded) {
            try {
                if (this.handle == "upload_file") {
                    var p = Math.floor((hasload + bytesLoaded) / allsize * 100);
                    if (bytesLoaded >= file.size) {
                        hasload += file.size;
                    }
                    if (p >= 100) {
                        p = 100;
                    }
                    Goes(p);
                }
                if (this.handle == "upload_video" || this.handle == "upload_video2") {
                    var p = Math.floor(bytesLoaded / file.size * 100);
                    if (p >= 100) {
                        p = 100;
                    }
                    $("#" + file.id).next().find(".percent").css("width", p).html(p + "%");
                }
            } catch (ex) {
                this.debug(ex);
            }
        };
        function fileQueueError(file, errorCode, message) {
            try {
                switch (errorCode) {
                    case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
                        alert("文件大小为0");
                        break;
                    case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
                        alert("您选择的文件大小为【" + GetSize(file.size) + "】，单个文件大小不能超过【" + swfs.settings.file_size_limit + "】");
                        break;
                    case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
                    case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
                        break;
                    default:
                        alert(message);
                        break;
                }

            } catch (ex) {
                this.debug(ex);
            }
        };
        function fileDialog() {

        };
        function prevDialog() {
            isdraged = true; //当弹出客户信息时，如果不加这句，在选完附件和图片后，弹层会消失
        };
        function InitSize() {
            var list = $("#" + panel + " .list .size");
            if (list.length > 0) {
                $("#" + panel).parent().removeClass("hidden");
            } else {
                $("#" + panel).parent().addClass("hidden");
            }
            var allsize = 0;
            $.each(list, function (i, info) {
                allsize += parseInt($(info).attr("val"));
            });
            $("#" + panel).next().html("共" + list.length + "个文件，总大小" + GetSize(allsize) + "，<a href='javascript:void(0)' onclick='" + panel.substring(0, panel.length - 1) + ".RemoveAll()' >全部取消</a>");
        };
        this.RemoveFile = function (o) {
            $(o).parent().parent().remove();
            var id = $(o).attr("val");
            InitSize();
            swfs.cancelUpload(id, false);
        };
        this.RemoveAll = function () {
            $("#" + panel).html("");
            var list = $("#" + panel + " .list .img img");
            $("#" + panel).parent().addClass("hidden");
            $.each(list, function (i, info) {
                swfs.cancelUpload($(info).attr("id"), false);
            });

        };
        swfs = new SWFUpload(swfuOption);
        this.swfu = swfs;
    };
    function Re_Upload() {
        $(".upload_product").removeClass("hidden");
        $(".upload_show").addClass("hidden");
        $(".img_container img").attr("src", "");
    };
    var upload = new Upload_File("upload_product");
    upload.swfu.handle = "upload_product";

</script>
</body>
</html>